package com.yq.day30.udp1.v1;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 16:29
 */
public class Demo02 {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = new DatagramSocket(9999);

        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, 0, bytes.length);

        datagramSocket.receive(datagramPacket);
        byte[] data = datagramPacket.getData();
        int offset = datagramPacket.getOffset();
        int length = datagramPacket.getLength();
        System.out.println(new String(data,offset,length));
        String s = new String(data, offset, length);
        System.out.println(datagramPacket.getSocketAddress());
        datagramSocket.close();


    }
}
